package cc.rengu.redp.bizimpl.csmc.controller;

import cc.rengu.redp.bizimpl.csmc.domain.CupsBrandFeeReportInfo;
import cc.rengu.redp.bizimpl.csmc.service.CupsBrandFeeReportService;
import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.domain.RedpResponse;
import cc.rengu.redp.common.utils.EasyExcelUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;


@Api(tags = "银联品牌服务费报表")
@RestController
@RequestMapping("/admin/csmc/report/CupsBrandFeeReport")
@Slf4j
public class CupsBrandFeeReportController extends BaseController {


    @Autowired
    private CupsBrandFeeReportService cupsBrandFeeReportService;


    @GetMapping("/list")
    public Map<String, Object> list(QueryRequest request, CupsBrandFeeReportInfo entity) {
        return getDataTable(cupsBrandFeeReportService.findByPage(request,entity));
    }

    @Log("导出")
    @PostMapping("/excel")
    @ResponseBody
    public RedpResponse gridExportAll(QueryRequest request, CupsBrandFeeReportInfo cupsBrandFeeReportInfo, HttpServletResponse response) {

        try {
            List<CupsBrandFeeReportInfo> CupsBrandFeeReportList = this.cupsBrandFeeReportService.findOrgChargeDetail(request, cupsBrandFeeReportInfo).getRecords();
            EasyExcelUtil.export(response, CupsBrandFeeReportList, "银联品牌服务费报表");
        } catch (IOException e) {
            String message = "导出Excel失败";
            log.error(message, e);
            return RedpResponse.getInstance().failure().message(message);
        }
        return RedpResponse.getInstance().success().message("导出Excel成功");
    }

}